package com.zy.project.system.permission.entity.base;

import com.alibaba.fastjson.annotation.JSONField;
import com.zy.core.data.jpa.support.entity.BaseEntity;
import com.zy.project.system.menu.entity.SystemMenu;
import com.zy.project.system.role.entity.SystemRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/**
 * 系统权限
 * Package: core.entity
 * <p>
 * Description： TODO
 * <p>
 * Author: zhangyu
 * <p>
 * Date: Created in 2018-9-1 22:39
 * <p>
 * Company: mingtu
 * <p>
 * Copyright: Copyright (c) 2018
 * <p>
 * Version: 0.0.1
 * <p>
 * Modified By:
 */
@Getter
@Setter
@MappedSuperclass
public class BaseSystemPermission extends BaseEntity {

    /**
     * 主键
     */
    @Id
    @GenericGenerator(name ="jpa-uuid", strategy = "uuid")
    @GeneratedValue(generator = "jpa-uuid")
    @Column(name = "id")
    private String id;

    /**
     * 权限名称
     */
    @Column(name = "name")
    private String name;

    /**
     * 创建时间
     */
    @Column(name = "create_date")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date createDate;

    /**
     * 更新时间
     */
    @Column(name = "update_date")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    private Date updateDate;

    /**
     * 描述
     */
    @Column(name = "description")
    private String description;

    /**
     * 权限与角色的关系,多个权限对应一个角色
     */
    @ManyToMany(targetEntity = SystemRole.class,
            mappedBy="permissions",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
    @JSONField(serialize=false)
    private Set<SystemRole> roles;

    /**
     * 权限的菜单集合
     */
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "permission")
    @JSONField(serialize=false)
    private Set<SystemMenu> menus;

}
